home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 15776 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.3 KB

  1. Path: wormer.fn.net!sysadmin@wormer.fn.net
  2. From: withheld@keepitpublic.com (Rusty Meathook)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: QUEUE
  5. Date: Sun, 21 Apr 1996 22:02:15 GMT
  6. Organization: Feist Connections
  7. Message-ID: <4le47i$u0@wormer.fn.net>
  8. References: <4lcg0j$7if@itsop2.its.brooklyn.cuny.edu>
  9. NNTP-Posting-Host: mark411.fn.net
  10. X-Newsreader: Forte Agent .99b.112
  11.  
  12. dzielins@its.brooklyn.cuny.edu (Daniel Zielinski) wrote:
  13.  
  14. >Can anyone tell me what's wrong with my removeQueue function?
  15.  
  16. >DataType
  17. >removeQueue(Queue *qp) {
  18. >    Node *np;
  19. >    DataType d;
  20. >
  21. >    assert(!emptyQueue(*qp));   <------- THIS IS THE LINE   
  22. >    np=qp->front;
  23. >    d=np->data;
  24. >    qp->front=np->next;
  25. >    if (qp->front==NULL)
  26. >        qp->rear=NULL;
  27. >    deleteNode(np);
  28. >    return d;
  29. >}
  30.  
  31. Why are you using assert() to test for that anyway?  Why not:
  32.  
  33. /* Untested code follows: */
  34. Queue *removeQueue(Queue *qp, DataType *d)
  35. {
  36.     Node *np;
  37.  
  38.     if (emptyQueue(*qp))
  39.         return (NULL);
  40.  
  41.     *d=qp->front->data;
  42.  
  43.     np=qp->front;
  44.     qp->front=qp->front->next;
  45.  
  46.     if (qp->front==NULL)
  47.         qp->rear=NULL;
  48.  
  49.     deleteNode(np);
  50.  
  51.     return (qp);
  52. }
  53.  
  54. Regardless, your implimentation is a lot more complex and splintered
  55. than it needs to be.  You might try implimenting your queue via a
  56. circular linked list so you don't have to fart around with the front
  57. and rear pointers....
  58.  
  59.